<?php
 class widget_menu extends CWidget {
	public function run() {
	  $avatar = "";
	  if(!Yii::app()->user->isGuest) {
	    $file_avatar = UserProfile::model()->getAvatar(Yii::app()->user->id);
	    $avatar = Yii::app()->baseUrl."/upload/avatar/thumbs_70x70/".$file_avatar;
	    if($file_avatar==NULL) {
	      $avatar = Yii::app()->baseUrl."/images/no-image.jpg";
	    }
	  }
	  $subject = Subject::model()->findAllByAttributes(array('deleted'=>0));
	  $sub_array = array();
	  if(!empty($subject)) {
	    $subjectID = isset($_GET['subjectID'])?$_GET['subjectID']:'';
	    foreach ($subject as $sub) {
	      $sub_array[] = array('label'=>$sub->subject,'url'=>array('/document/index/subjectID/'.md5($sub->ID)),
	          'active'=>Yii::app()->controller->id=='document' && md5($sub->ID)==$subjectID);
	    }
	    $sub_array[] = array('label'=>'','itemOptions'=>array('class'=>'divider'));
	    $sub_array[] = array('label'=>'Tất cả','url'=>array('/document'),
	    			'active'=>Yii::app()->controller->id=='document' && Yii::app()->controller->action->id=='index' && $subjectID=='');
	  }
	  $this->render('widget_menu', array('avatar'=>$avatar, 'subject'=>$sub_array));
	}
} 
?>